package com.sg.service.biz.framework.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.sg.common.util.RedisUtil;
import com.sg.dto.biz.framework.req.*;
import com.sg.dto.biz.framework.res.*;
import com.sg.service.base.framework.MRoleMemberService;
import com.sg.service.base.framework.MSpaceService;
import com.sg.common.exception.Assert;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.stream.Collectors;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class InterfaceModeServiceImpl implements com.wicket.okrframework.biz.service.InterfaceModeService {
    @Resource
    private RedisUtil redisUtil;
    @Resource
    private MRoleMemberService mRoleMemberService;
    @Resource
    private NbInterfaceMode nbInterfaceMode;
    @Resource
    private MSpaceService mSpaceService;
//@Resource
    //private MCustomFields4Service mCustomFields4Service;

    /**
     * D1-1执行清除底层框架服务公共字段内存(公共)[4994]
     * gen by moon at 10/23/2022, 9:10:47 PM
     */
    @Trace(operationName = "D1-1执行清除底层框架服务公共字段内存(公共)")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ImplementBottomPublicFieldClearMemoryComRespDto implementBottomPublicFieldClearMemoryCom(ImplementBottomPublicFieldClearMemoryComReqDto reqDto) {


        //步骤0: M1执行清除底层框架服务公共字段内存(特殊方法） - implementBottomPublicFieldClearMemory
        //ModelCode: clearFieldCache
        ImplementBottomPublicFieldClearMemoryRespDto clearFieldCacheRes = null;
        ImplementBottomPublicFieldClearMemoryReqDto clearFieldCacheReq = new ImplementBottomPublicFieldClearMemoryReqDto();
        if (reqDto != null) {
            clearFieldCacheReq.setSpaceId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:387982_1
            clearFieldCacheReq.setAppId(reqDto.getAppId());//SimpleFieldAssign//sourceId:387983_1
        }

        /*M1执行清除底层框架服务公共字段内存(特殊方法）[4993]  用于平台查询数据时，清除当前特定字段的公共缓存 */

        clearFieldCacheRes = nbInterfaceMode.implementBottomPublicFieldClearMemory(clearFieldCacheReq);


        ImplementBottomPublicFieldClearMemoryComRespDto retData = new ImplementBottomPublicFieldClearMemoryComRespDto();


        return retData;
    }

    /**
     * D1新增框架内存业务数据(公共)[9136]
     * gen by moon at 4/3/2024, 1:35:02 PM
     */
    @Trace(operationName = "D1新增框架内存业务数据(公共)")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public AddFrameWorkMemoryBusinessDataComRespDto addFrameWorkMemoryBusinessDataCom(AddFrameWorkMemoryBusinessDataComReqDto reqDto) {


        //步骤0: M1新增框架内存业务数据（特殊方法） - addFrameWorkMemoryBusinessData
        //ModelCode: addMemoryBusinessData
        AddFrameWorkMemoryBusinessDataRespDto addMemoryBusinessDataRes = null;
        AddFrameWorkMemoryBusinessDataReqDto addMemoryBusinessDataReq = new AddFrameWorkMemoryBusinessDataReqDto();
        if (reqDto != null) {
            addMemoryBusinessDataReq.setDataObjectBatchCode(reqDto.getDataObjectBatchCode());//SimpleFieldAssign//sourceId:1690187_1
            addMemoryBusinessDataReq.setBusinessDataObject(reqDto.getBusinessDataObject());//SimpleFieldAssign//sourceId:1690188_1
            addMemoryBusinessDataReq.setIsDataList(reqDto.getIsDataList());//SimpleFieldAssign//sourceId:1690189_1
        }
        if (reqDto != null && reqDto.getMemoryBusinessDataList() != null && !CollectionUtil.isEmpty(reqDto.getMemoryBusinessDataList())) {
            addMemoryBusinessDataReq.setMemoryBusinessDataList(reqDto.getMemoryBusinessDataList().stream().map(item -> BeanUtil.toBean(item, MemoryBusinessDataDto.class)).collect(Collectors.toList()));//objList-to-objLists//sourceId:1690186_1
        }

        /*M1新增框架内存业务数据（特殊方法）[9135]   */

        addMemoryBusinessDataRes = nbInterfaceMode.addFrameWorkMemoryBusinessData(addMemoryBusinessDataReq);


        AddFrameWorkMemoryBusinessDataComRespDto retData = new AddFrameWorkMemoryBusinessDataComRespDto();


        return retData;
    }

    /**
     * D1查询框架内存业务数据列表(公共)[9140]
     * gen by moon at 4/2/2024, 11:33:51 PM
     */
    @Trace(operationName = "D1查询框架内存业务数据列表(公共)")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public QueryFrameWorkMemoryBusinessDataListComRespDto queryFrameWorkMemoryBusinessDataListCom(QueryFrameWorkMemoryBusinessDataListComReqDto reqDto) {


        QueryFrameWorkMemoryBusinessDataListRespDto queryMemoryBusinessDatasRes_1 = null;
//步骤0: M1查询框架内存业务数据列表(特殊方法） - queryFrameWorkMemoryBusinessDataList
        //ModelCode: queryMemoryBusinessDatas
        QueryFrameWorkMemoryBusinessDataListRespDto queryMemoryBusinessDatasRes = null;
        QueryFrameWorkMemoryBusinessDataListReqDto queryMemoryBusinessDatasReq = new QueryFrameWorkMemoryBusinessDataListReqDto();
        if (reqDto != null) {
            queryMemoryBusinessDatasReq.setMemoryBusinessResDataList(reqDto.getMemoryBusinessResDataList());//list-field-assign//sourceId:1690876_1
            queryMemoryBusinessDatasReq.setDataObjectBatchCode(reqDto.getDataObjectBatchCode());//SimpleFieldAssign//sourceId:1690877_1
            queryMemoryBusinessDatasReq.setBusinessDataObject(reqDto.getBusinessDataObject());//SimpleFieldAssign//sourceId:1690878_1
        }

        /*M1查询框架内存业务数据列表(特殊方法）[9139]   */
        Assert.isNull(queryMemoryBusinessDatasReq.getDataObjectBatchCode(), "D1查询框架内存业务数据列表(公共)-M1查询框架内存业务数据列表(特殊方法）-数据对象批次标识不能为空", false);
        Assert.isNull(queryMemoryBusinessDatasReq.getBusinessDataObject(), "D1查询框架内存业务数据列表(公共)-M1查询框架内存业务数据列表(特殊方法）-业务数据对象不能为空", false);
        queryMemoryBusinessDatasRes = nbInterfaceMode.queryFrameWorkMemoryBusinessDataList(queryMemoryBusinessDatasReq);


        queryMemoryBusinessDatasRes_1 = queryMemoryBusinessDatasRes;

        QueryFrameWorkMemoryBusinessDataListComRespDto retData = new QueryFrameWorkMemoryBusinessDataListComRespDto();
        if (queryMemoryBusinessDatasRes_1 != null) {
            retData.setMemoryBusinessResDataList(queryMemoryBusinessDatasRes_1.getMemoryBusinessResDataList().stream().map(item -> BeanUtil.toBean(item, MemoryBusinessResDataDto.class)).collect(Collectors.toList()));//objList-to-objLists//sourceId:1690915_1
        }


        return retData;
    }

    /**
     * D1分段查询框架服务数据对象(公共)[9688]
     * gen by moon at 6/2/2024, 10:28:33 PM
     */
    @Trace(operationName = "D1分段查询框架服务数据对象(公共)")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ImplementGeneralSegBaseDataComRespDto implementGeneralSegBaseDataCom(ImplementGeneralSegBaseDataComReqDto reqDto) {


        ImplementGeneralSegBaseDataRespDto subsectionQueryBusinessDataSetRes_1 = null;
//步骤0: M1执行分段查询框架服务数据对象 - implementGeneralSegBaseData
        //ModelCode: subsectionQueryBusinessDataSet
        ImplementGeneralSegBaseDataRespDto subsectionQueryBusinessDataSetRes = null;
        ImplementGeneralSegBaseDataReqDto subsectionQueryBusinessDataSetReq = new ImplementGeneralSegBaseDataReqDto();
        if (reqDto != null) {
            subsectionQueryBusinessDataSetReq.setBusinessDataSetTableName(reqDto.getBusinessDataSetTableName());//SimpleFieldAssign//sourceId:1830400_1
            subsectionQueryBusinessDataSetReq.setDatasNum(reqDto.getDatasNum());//SimpleFieldAssign//sourceId:1830401_1
            subsectionQueryBusinessDataSetReq.setOrderFieldName(reqDto.getOrderFieldName());//SimpleFieldAssign//sourceId:1830402_1
            subsectionQueryBusinessDataSetReq.setOrderRule(reqDto.getOrderRule());//SimpleFieldAssign//sourceId:1830403_1
            subsectionQueryBusinessDataSetReq.setBusinessDataSetPrimaryKeyName(reqDto.getBusinessDataSetPrimaryKeyName());//SimpleFieldAssign//sourceId:1830404_1
            subsectionQueryBusinessDataSetReq.setLastDataObjectId(reqDto.getLastDataObjectId());//SimpleFieldAssign//sourceId:1830405_1
            subsectionQueryBusinessDataSetReq.setRefCustomField1(reqDto.getRefCustomField1());//SimpleFieldAssign//sourceId:1830406_1
            subsectionQueryBusinessDataSetReq.setRefCustomFieldValue1(reqDto.getRefCustomFieldValue1());//SimpleFieldAssign//sourceId:1830414_1
            subsectionQueryBusinessDataSetReq.setRefCustomField2(reqDto.getRefCustomField2());//SimpleFieldAssign//sourceId:1830407_1
            subsectionQueryBusinessDataSetReq.setRefCustomFieldValue2(reqDto.getRefCustomFieldValue2());//SimpleFieldAssign//sourceId:1830415_1
            subsectionQueryBusinessDataSetReq.setRefCustomField3(reqDto.getRefCustomField3());//SimpleFieldAssign//sourceId:1830408_1
            subsectionQueryBusinessDataSetReq.setRefCustomFieldValue3(reqDto.getRefCustomFieldValue3());//SimpleFieldAssign//sourceId:1830416_1
            subsectionQueryBusinessDataSetReq.setRefCustomField4(reqDto.getRefCustomField4());//SimpleFieldAssign//sourceId:1830409_1
            subsectionQueryBusinessDataSetReq.setRefCustomFieldValue4(reqDto.getRefCustomFieldValue4());//SimpleFieldAssign//sourceId:1830417_1
            subsectionQueryBusinessDataSetReq.setRefCustomField5(reqDto.getRefCustomField5());//SimpleFieldAssign//sourceId:1830410_1
            subsectionQueryBusinessDataSetReq.setRefCustomFieldValue5(reqDto.getRefCustomFieldValue5());//SimpleFieldAssign//sourceId:1830418_1
            subsectionQueryBusinessDataSetReq.setRefCustomField6(reqDto.getRefCustomField6());//SimpleFieldAssign//sourceId:1830411_1
            subsectionQueryBusinessDataSetReq.setRefCustomFieldValue6(reqDto.getRefCustomFieldValue6());//SimpleFieldAssign//sourceId:1830419_1
            subsectionQueryBusinessDataSetReq.setRefCustomField7(reqDto.getRefCustomField7());//SimpleFieldAssign//sourceId:1830412_1
            subsectionQueryBusinessDataSetReq.setRefCustomFieldValue7(reqDto.getRefCustomFieldValue7());//SimpleFieldAssign//sourceId:1830420_1
            subsectionQueryBusinessDataSetReq.setRefCustomField8(reqDto.getRefCustomField8());//SimpleFieldAssign//sourceId:1830413_1
            subsectionQueryBusinessDataSetReq.setRefCustomFieldValue8(reqDto.getRefCustomFieldValue8());//SimpleFieldAssign//sourceId:1830421_1
        }
        if (reqDto != null && reqDto.getOutputDataList() != null && !CollectionUtil.isEmpty(reqDto.getOutputDataList())) {
            subsectionQueryBusinessDataSetReq.setOutputDataList(reqDto.getOutputDataList().stream().map(item -> BeanUtil.toBean(item, OutputDataDto.class)).collect(Collectors.toList()));//objList-to-objLists//sourceId:1830422_1
        }

        /*M1执行分段查询框架服务数据对象[9687]  用于分段查询业务数据对象 */
        Assert.isNull(subsectionQueryBusinessDataSetReq.getBusinessDataSetTableName(), "D1分段查询框架服务数据对象(公共)-M1执行分段查询框架服务数据对象-数据对象表名不能为空", false);
        Assert.isNull(subsectionQueryBusinessDataSetReq.getDatasNum(), "D1分段查询框架服务数据对象(公共)-M1执行分段查询框架服务数据对象-数据条数不能为空", false);
        Assert.isNull(subsectionQueryBusinessDataSetReq.getOrderFieldName(), "D1分段查询框架服务数据对象(公共)-M1执行分段查询框架服务数据对象-排序字段名不能为空", false);
        Assert.isNull(subsectionQueryBusinessDataSetReq.getOrderRule(), "D1分段查询框架服务数据对象(公共)-M1执行分段查询框架服务数据对象-排序规则不能为空", false);
        Assert.isNull(subsectionQueryBusinessDataSetReq.getBusinessDataSetPrimaryKeyName(), "D1分段查询框架服务数据对象(公共)-M1执行分段查询框架服务数据对象-数据对象主键名不能为空", false);
        Assert.isNull(subsectionQueryBusinessDataSetReq.getRefCustomFieldValue7(), "D1分段查询框架服务数据对象(公共)-M1执行分段查询框架服务数据对象-入参自定义字段值7不能为空", false);
        Assert.isNull(subsectionQueryBusinessDataSetReq.getRefCustomField8(), "D1分段查询框架服务数据对象(公共)-M1执行分段查询框架服务数据对象-入参自定义字段8不能为空", false);
        Assert.isNull(subsectionQueryBusinessDataSetReq.getRefCustomFieldValue8(), "D1分段查询框架服务数据对象(公共)-M1执行分段查询框架服务数据对象-入参自定义字段值8不能为空", false);
        subsectionQueryBusinessDataSetRes = nbInterfaceMode.implementGeneralSegBaseData(subsectionQueryBusinessDataSetReq);


        subsectionQueryBusinessDataSetRes_1 = subsectionQueryBusinessDataSetRes;

        ImplementGeneralSegBaseDataComRespDto retData = new ImplementGeneralSegBaseDataComRespDto();
        if (subsectionQueryBusinessDataSetRes_1 != null) {
            retData.setBaseDataList(subsectionQueryBusinessDataSetRes_1.getBaseDataList().stream().map(item -> BeanUtil.toBean(item, BaseDataDto.class)).collect(Collectors.toList()));//objList-to-objLists//sourceId:1830447_1
        }


        return retData;
    }


    //
}
